<?
if($_POST["selbox"] != ''){
	
	//reauth the user, if $_SESSION["reauthed"] != Y bail out
	if($check_me_authed == "OK"){
		
		$today_date 			= date("d-m-Y");
		
		$srcDbSequence      = "MST_SEQUENCE";
  	$srcDbHdr			      = "SLS_DLVR_HDR";
    $srcDbHdrLog	      = "LOG_SLS_DLVR_HDR";
    $srcDbDtl           = "SLS_DLVR_DTL";
    $dstDbHdr           = "SLS_ORDER_HDR";
    $dstDbSubDtl        = "SLS_ORDER_SUB_DTL";
  
    $UID     = unserialize($_SESSION["serUID"]);
    $userId  = $UID->getUID();
    
    $COracle = new oracleDb;
    $COracle->init($_SESSION["ORCL"], 
                   $_SESSION["OPASS"],
                   $_SESSION["SID"],
                   _NO_COMMENT);
    
    if($COracle->connect()){
		
			if(sizeof($_POST["selbox"]) == 0){
				
				usrDie("Error: nothing to be cancel");
			}else{
				
				foreach($_POST["selbox"] as $cclThisJobId){
					
					/**
      		* Fetch global header
      		* And check the status if it is valid
      		* where STATUS = _NOT_ACTIVE 
      		*
      		*/
      		$CFetchers->fetchLstDataHeader($COracle,
                                         $cclThisJobId,
                                         $srcDbHdr,
                                         $nHeader,
                                         $lstHeader);
					
					if($lstHeader["STATUS"][0] != _ACTIVE){
						
						usrDie("Error: Tx with JobId: ".$cclThisJobId." is not yet approved.");
					}else{
						
						$CHandlers->procCancel($COracle,
            						           $cclThisJobId,
            						           $userId,
            						           $srcDbHdr);
						
						/**
            * Extra work is to update the picked
            * jobId and check if dlvrQty
            * Greater than 0
            * YES: set status to _OUTSTANDING
            * NO : set status to _ACTIVE
            *
            */
            $isCancel = true;
            require("controllers/processReceives.php");
                       
            /**
            * Insert Log
            *
            */
            $CHandlers->insToDbLog($COracle,
                                   $today_date,
                                   $cclThisJobId,
                                   $userId,
                                   $_SERVER["REMOTE_ADDR"],
                                   _CANCEL_MODE,
                                   $srcDbHdrLog); 
					}
					
				}
				
				$COracle->commit();
				
				if($COracle->getStatus() == true){
  
      	  usrMsg("Cancel Complete");
      	}else{
      	  
      	  usrMsg("Cancel Process Interupted");
      	}
      	
      	$COracle->dc();
				
				//GoBack("2","../".$_SESSION["source_caller"]);
			}
		}else{
			
			usrDie("Error: Oracle connection failed");
		}
	}else{
		
		usrDie("NOT AUTHED");
	}
}
?>